<?php
class Add_Action_Controller extends Engine_Action_ControllerAbstract

{
  
private $article; // obj
     
    public function setArticleModel ()
    {   
        $this->article = new Article_model();
        $this->article->setCategory($this->get['articleCat']);
        $this->article->setArticleName( $this->get['articleName'] );
        $this->article->setTags($this->get['articleTags'] );
        $this->article->setArticleText($this->get['addArticle'] );
    } 
  
      public function run()
      {
         // вызывает модель где все главные параметры
         $this->setInfoModel('Добавить Сообщение');
        // В зависимости от названия класса выводит шаблон
         $this->view->setRenderTemplate( __CLASS__);
         
         // использовать Add_Article_Data_Mapper
         
         if (    $this->view->isReg === true && 
                 isset($this->get['articleCat'])  && isset($this->get['articleName']) &&
                 isset($this->get['articleTags']) && isset($this->get['addArticle']))  {
            $this->setArticleModel();
            $addArticleDataMapper = new Article_Data_Mapper();
            $addArticleDataMapper->setAddInfo(
                                            $this->auth->getUserId(),
                                            $this->article->getCategory(),
                                            $this->article->getArticleName() ,
                                            $this->article->getTags(),
                                            $this->article->getArticleText() 
                                            );
            
            $addArticleDataMapper->save();
            
            if ( $addArticleDataMapper->getMapperResult() !== true &&
                 isset($this->get['articleCat'])  && isset($this->get['articleName']) &&
                 isset($this->get['articleTags']) && isset($this->get['addArticle'])  ) {
                 $this->view->error = $addArticleDataMapper->getError();
                 } 
            elseif ($addArticleDataMapper->getMapperResult() == true){
                header('Location:/add/');
            }     
     }
      
          
     }
}